from django.shortcuts import render
from django.contrib.auth.views import LoginView, LogoutView
# Create your views here.
from users.forms import DmallLoginForm


class DmallLoginView(LoginView):
    # 登录视图
    form_class = DmallLoginForm
    template_name = 'users/login.html'
    redirect_authenticated_user = True   # 登录之后不允许访问
    
    def get_success_url(self) -> str:
        redirect_to = self.request.GET.get('redirect_to', None)
        if redirect_to and redirect_to == "/users/add_fav/":
            return '/'
        elif redirect_to:
            return redirect_to
        else:
            return '/'
    

class DmallLogoutView(LogoutView):
    # 退出登录
    template_name = 'users/logout.html'
    redirect_authenticated_user = True




